﻿using CodeGenerator.Models;
using CodeGenerator.Template;
using CodeGenerator.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CodeGenerator.Generators
{
    internal class MVC3BLGenerator : Generator
    {
        public override void Generate(int projectId, string outputPath)
        {
            MetaData modelForBL = new MetaData();
            modelForBL.Models = this.GetClassesByProjectId(projectId);
            modelForBL.Project = this.GetProjectByProjectId(projectId);

            List<LookupClassModel> list = this.GetLookupClass(modelForBL.Models);

            Generate(modelForBL, list, outputPath);
        }

        public void Generate(MetaData modelForBL, List<LookupClassModel> list, string outputPath)
        {
            if (!(modelForBL.Models == null || modelForBL.Project == null || list == null))
            {
                outputPath = Path.Combine(outputPath, modelForBL.Project.ProjectName);
                DirectoryExt.CreateIfMissing(outputPath);

                GenerateFiles(modelForBL, list, "Service", outputPath);
                GenerateFiles(modelForBL, list, "Service.Dto", outputPath);
                GenerateFiles(modelForBL, list, "Service.Properties", outputPath);
                GenerateFiles(modelForBL, list, "Service.Util", outputPath);
            }
        }
    }
}
